package com.nowcoder.community.dao;

import com.nowcoder.community.entity.LoginTicket;
import org.apache.ibatis.annotations.*;

/**
 * @author 花木凋零成兰
 * @date 2024/3/9 16:43
 */
@Mapper
@Deprecated     // 声明 组件不推荐使用
public interface LoginTicketMapper {

    /**
     * 插入一条 ticket
     * @param loginTicket
     * @return
     */
    @Insert("insert into login_ticket(user_id, ticket, status, expired) values (#{userId}, #{ticket}, #{status}, #{expired})")
    @Options(useGeneratedKeys = true, keyProperty = "id")   // 配置自动生成id并注入给loginTicket
    int insertLoginTicket(LoginTicket loginTicket);

    /**
     * 根据ticket查询LoginTicket
     * @param ticket
     * @return
     */
    @Select("select * from login_ticket where ticket = #{ticket}")
    LoginTicket selectByTicket(String ticket);

    /**
     * 更新loginTicket状态
     * @param ticket
     * @param status
     * @return
     */
    @Update("update login_ticket set status = #{status} where ticket = #{ticket}")
    int updateStatus(String ticket, int status);

}
